<?php

/**
 * LoginForm class.
 * LoginForm is the data structure for keeping
 * user login form data. It is used by the 'login' action of 'SiteController'.
 */
class RegisterForm extends CFormModel
{
	public $email;
	public $password;
	public $password1;
	public $domain;
	
	private $_identity;

	/**
	 * Declares the validation rules.
	 * The rules state that username and password are required,
	 * and password needs to be authenticated.
	 */
	public function rules()
	{
		return array(
			array('email,', 'required','message'=>'请填写邮箱做为登陆帐号'), 
			array('password', 'required','message'=>'请设置登陆密码'), 
			array('password', 'length','min'=>6,'tooShort'=>'密码长度至少需要{min}位'), 
			array('domain', 'required','message'=>'请输入5-9位字母或数字.'), 
			array('password1', 'required','on'=>'wbregister','message'=>'这个不能空白的哦^_^'), 
			array('password1', 'compare', 'on'=>'wbregister','compareAttribute'=>'password','message'=>'你二次的输的不一样耶。^_^'),
			array('email', 'email'),
			array('email', 'EMongoUniqueValidator','message'=>'这个邮箱我认识，TA已经注册过了'),
			array('domain', 'match', 'pattern'=>'/^\w{4,20}$/','message'=>'请确认是4-20个英文字符或数字'),
			array('domain', 'EMongoUniqueValidator','message'=>'太抢手了，又被别人占了，换一个吧！'),
			
//			array('password1', 'compare', 'compareAttribute'=>'password'),
		);
	}

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
			'email'=>'邮箱',
			'password'=>'密码',
			'password1'=>'确认密码',
			'domain'=>'个性域名',
		);
	}

	
 
	public function register(){
	    $user = new User;
//		  $user->muid=NumGen::getUserId();
	    $user->email = $this->email;
	    $user->password = md5($this->password);
	    $user->domain = $this->domain;
	    return $user->validate() && $user->save();
	}
	
	public function wbRegister($user){
	    //$user = new User;
		  //$user->muid=NumGen::getUserId();
	    $user->email = $this->email;
	    $user->password = md5($this->password);
	    //$user->name = $user->muid;
	    $user->domain = $this->domain;
	    //$user->_id=$_id;
	    return $user->validate() && $user->save();
	}
	
	public function model ($className = __CLASS__)
    {
        return User::model();
    }
}
